<template>
  <div class="search">
    <f-form ref="form" :action="api.invoice" :form-key="this.formItem.invoiceId" :file-ids="fileIds">
      <f-form-item label="发票抬头" name="invoiceTitle" :required="true" :value="formItem.invoiceTitle"/>
      <f-form-item label="企业税号" name="creditCode" :required="true" :value="formItem.creditCode" v-if="formItem.invoiceType==2"/>
      <f-form-item label="发票类型" name="invoiceType" type="select" data-type="number" :required="true" :data="invoiceTypeData" :value="formItem.invoiceType" label-key="label" value-key="value"/>
      <f-form-item label="发票内容" name="invoiceBody" :required="true" :value="formItem.invoiceBody"/>
      <f-form-item label="发票金额" name="invoiceAmount" type="number" :value="formItem.invoiceAmount"/>
      <f-form-item label="收件人" name="consignee" :value="formItem.consignee"/>
      <f-form-item label="企业地址" name="address" :value="formItem.address"/>
      <f-form-item label="联系电话" name="telephone" :value="formItem.telephone"/>
      <f-form-item label="快递公司" name="expressCompany" :value="formItem.expressCompany"/>
      <f-form-item label="快递单号" name="expressNo" :value="formItem.expressNo"/>
      <f-form-item label="备注" name="remark" :value="formItem.remark"/>
      <f-form-item label="开票状态" name="invoiceState" :required="true" type="radio" v-if="loaded"  :data="api.invoice.invoiceState" :value.sync="formItem.invoiceState"/>
    </f-form>
  </div>
</template>

<script>
  export default {
    name: 'InvoiceForm',
    props: {},
    data() {
      return {
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载轮播图组件
        fileIds: [],//上传文件ID
        formItem: this.getFormItem(),
        invoiceTypeData: [{ label: '个人发票', value: 1 }, { label: '企业发票', value: 2 }]
      }
    },
    methods: {
      getFormItem() {
        return {
          invoiceId: '',
          invoiceTitle: '',
          invoiceType: 1,
          invoiceAmount: 0,
          consignee: '',
          address: '',
          invoiceKind: '',
          invoiceNo: '',
          telephone: '',
          expressCompany: '',
          expressNo: '',
          remark: ''
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        this.isAdd = true
        if (data && data.invoiceId) {
          this.$refs.form.getDetails({ invoiceId: data.invoiceId }, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({},callback)
      }
    },
    created() {

    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
